package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_DISPATCH_PATRONS_FROM_CROSS,desc = "派遣出战门客")
public class DouLuoDaLuDispatchPatronsCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        DouLuoDaLuProto.DouLuoDaLuDispatchPatronsCrossRespMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuDispatchPatronsCrossRespMsg.parseFrom(packet.getBytes());
        if (reqMsg.getRet() != 0) {
            //重置门客次数与玩家派遣次数
            player.getModule(DouLuoDaLuModule.class).restoreTimes(reqMsg.getPatronsId(), reqMsg.getBattleType());
        } else {
            //门客的珍兽鱼类绑定一下活动
            player.getModule(VehicleModule.class).bindPatrons(reqMsg.getPatronsId(), DouLuoDaLuMgr.getActivityInfo().getActivityId());
        }

        DouLuoDaLuProto.DouLuoDaLuDispatchPatronsRespMsg.Builder respMsg = DouLuoDaLuProto.DouLuoDaLuDispatchPatronsRespMsg.newBuilder();
        respMsg.setRet(reqMsg.getRet());
        //respMsg.setBattleType(reqMsg.getBattleType());
        if(reqMsg.hasPatrons()) {
            respMsg.setPatrons(reqMsg.getPatrons());
        }
        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_DISPATCH_PATRONS, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
